package Application;

import java.io.*;

public class ReadFileToString {
    public static String readFile(String path){
        StringBuffer sb = new StringBuffer("");
        String line;
        File file = new File(path);
        FileInputStream fis =null;
        BufferedReader reader =null;
        try {
            fis = new FileInputStream(file);
            reader = new BufferedReader(new InputStreamReader(fis));
            line = reader.readLine();
            while(line!=null){
                sb.append(line);
                sb.append("\n");
                line = reader.readLine();
            }
        }catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(reader!=null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(fis!=null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return sb.toString();
    }
}
